package com.snooker.snooker.controller;

import com.github.pagehelper.*;
import com.snooker.snooker.dto.*;
import com.snooker.snooker.service.EventService;
import com.snooker.snooker.vo.GetEventIdVo;
import io.swagger.annotations.*;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 比赛信息-controller
 * @Param:
 * @return:
 * @Author: fenghouzhi
 * @Date: 7:21 PM 2018/11/13
 */
@Slf4j
@RestController
@Api(tags = "比赛信息")
@RequestMapping(value = "/event")
public class EventController {

  @Resource
  private EventService eventService;

  @ApiOperation(value = "获取赛季内所有比赛信息-含分页")
  @PostMapping("/events")
  ResponseDto getAllEvent(@RequestBody GetEventIdVo getEventIdVo) {
    log.info("page param---{}", getEventIdVo);
    PageHelper.startPage(getEventIdVo.getPageRequestVo().getPageNum(),
        getEventIdVo.getPageRequestVo().getPageSize());
    List<EventDto> eventList = eventService.getAllEventDto(getEventIdVo.getSeason());
    PageInfo<EventDto> pageInfo = new PageInfo<EventDto>(eventList);
    return ResponseDto.ok("success", pageInfo);
  }

  @ApiOperation(value = "获取赛季内所有比赛EventId")
  @GetMapping("/events/id/{season}")
  ResponseDto getAllEventId(@PathVariable Integer season) {
    log.info("要查看的赛季---{}", season);
    List<Integer> eventList = eventService.getAllEventId(season);
    return ResponseDto.ok("success", eventList);
  }

  @ApiOperation(value = "获取单站比赛的回合轮次信息")
  @GetMapping("/events/game/{eventId}")
  ResponseDto getGameForEvent(@PathVariable Integer eventId) {
    log.info("要查看的比赛ID---{}", eventId);
    EventDto eventDto = eventService.getEventDtoByEventId(eventId);
    if (eventDto != null) {
      return ResponseDto.ok("success", eventDto);
    } else {
      return ResponseDto.warn("未查询到该站比赛的相关信息");
    }
  }

}
